package common;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

/**
 * Created by Administrator on 2017-11-27.
 */
public class Page {
    public int currentPageNow(HttpServletRequest request,int count) throws SQLException {
        //先获取总记录数
        int allPage=1;
        int pageNow=0;
        //共分多少页

        if (count%10!=0){
            allPage=count/10+1;
        }else if(count!=0){
            allPage=count/10;
        }
        request.setAttribute("allPage",allPage);
        try {
            pageNow=Integer.parseInt(request.getParameter("page"));
        }catch (Exception e){
            pageNow=1;
        }
        //如果当前页数小于1，则置为为1
        if (pageNow<1){
            pageNow=1;
        }
        if (pageNow>allPage){
            pageNow=allPage;
        }
        request.setAttribute("pageNow",pageNow);
        request.setAttribute("count",count);
        return pageNow;
    }
}
